<template>
  <div class="edit">
    <el-tabs :tab-position="'left'">
      <el-tab-pane label="基本信息登记">
        <basic-information :type="'edit'" :formObj="editObj" @handleNext="handleEdit"></basic-information>
      </el-tab-pane>
      <el-tab-pane label="借阅人登记">
        <borrower :type="'edit'"
                  :formObj="editObj"
                  :idContinue="idContinue"
                  @handleDel="handleDel($event,'people')"
                  @handleEdit="handleEdit"
                  @handleAdd="handleEditAdd"
                  @handleNext="handleNext(2)"></borrower>
      </el-tab-pane>
      <el-tab-pane label="借阅物品登记">
        <borrowing-goods :type="'edit'"
                         :formObj="editObj"
                         :idContinue="idContinue"
                         @handleDel="handleDel($event,'continue')"
                         @handleEdit="handleEdit"
                         @handleAdd="handleEditAdd"
                         @handleNext="handleNext(3)"></borrowing-goods>
      </el-tab-pane>
      <el-tab-pane label="资料提交">
        <data-submit :type="'edit'"
                     :formObj="editObj"
                     :idContinue="idContinue"
                     @handleAdd="handleEditAdd"
                     @handleDel="handleDel($event,'file')"
                     @handleComplete="handleComplete"></data-submit>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import DataSubmit from './dataSubmit'
import BorrowingGoods from './borrowingGoods'
import Borrower from './borrower'
import BasicInformation from './basicInformation'
import { editBorrowt, editListAdd, editListDel } from '../../../../../api/house/paperBorrow'

export default {
  name: 'editPBRegister',
  props: {
    editObj: {
      type: Object,
      default: () => ({})
    },
    idContinue: {
      type: String,
      default: ''
    }
  },
  components: {
    DataSubmit,
    BorrowingGoods,
    Borrower,
    BasicInformation
  },
  methods: {
    handleEdit (val) {
      // 基础属性修改
      editBorrowt(val).then(res => {
        this.$message.success('修改成功！')
        this.$emit('handleSuccess', 'edit')
      })
    },
    handleDel (row, type) {
      // 删除
      editListDel({ id: row.id, page: type }).then(res => {
        this.$message.success('删除成功！')
        this.$emit('handleSuccess', 'del')
      }).catch(() => {
      })
    },
    handleEditAdd (val) {
      // 修改新增
      editListAdd(val).then(res => {
        this.$message.success('修改成功！')
        this.$emit('handleSuccess', 'edit')
      })
    },
    handleNext (val) {
      // 修改新增
      editListAdd(this.editObj).then(res => {
        this.$message.success('修改成功！')
        this.$emit('handleSuccess')
      })
    },
    handleComplete () {
      // 完成，关闭弹窗
      this.$emit('handleComplete', this.formObj)
    },
    handleEmpty () {
      this.setActive = 1
      this.formObj = {}
    }
  }
}
</script>

<style lang="scss" scoped>
  .edit {
    ::v-deep .el-tab-pane {
      padding-right: 20px;
      overflow-y: auto;
      height: calc(100vh - 80px);
      padding-bottom: 15px;
    }
  }
</style>
